<template>
  <div class="info" v-loading="loading">
    <div>
      <div class="row mb20">
        <div class="l" @click="handleAdd">
          <i class="el-icon-circle-plus-outline"></i>添加
        </div>
        <div class="tip">( 结算规则以第一条数据为准 )</div>
      </div>
      <el-table
        border
        :data="tableData"
        :header-cell-style="{
          'text-align': 'center',
        }"
        :cell-style="{ 'text-align': 'center' }"
        style="width: 100%"
        highlight-current-row
      >
        <el-table-column type="selection" min-width="5%"> </el-table-column>
        <el-table-column prop="id" label="id" min-width="10%">
        </el-table-column>
        <el-table-column prop="mch_id" label="商户id" min-width="10%">
        </el-table-column>
        <el-table-column prop="class_text" label="分类" min-width="10%">
        </el-table-column>
        <el-table-column label="规则预览" min-width="10%">
          <template slot-scope="scope">
            <div>手续费：{{ scope.row.extend.mch.fee }}</div>
            <div>服务费：{{ scope.row.extend.mch.ratio }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="time" label="时间" min-width="20%">
        </el-table-column>
        <el-table-column label="操作" min-width="30%">
          <template slot-scope="scope">
            <div class="caozuo">
              <div class="handleEdit hand_cs" @click="handleEdit(scope.row)">
                查看
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <Pagination :page="page" @onCurrentChange="handleCurrentChange" />
      </div>

      <el-dialog
        class="editDialog"
        :title="title"
        :visible.sync="changeDialog"
        width="70%"
        append-to-body
        :close-on-click-modal="false"
      >
        <AddEditDialog
          v-if="changeDialog"
          @closeAddSettle="closeAddSettle"
          :rowData="rowData"
          :storeId="storeId"
        ></AddEditDialog>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination.vue";
import AddEditDialog from "./settle_addEdit.vue";
import { settleList } from "@/api/merchant";
export default {
  components: { Pagination, AddEditDialog },
  props: ["storeId"],
  data() {
    return {
      loading: true,
      title: "",
      page: {
        total: 0,
        pageNum: 1, // 当前页数
        pageSize: 10, // 每页的条数
      },
      tableData: [],
      rowData: {},
      changeDialog: false,
    };
  },
  methods: {
    async settleList() {
      const { data, err } = await settleList({
        mid: this.storeId,
        page: this.page.pageNum,
      });
      if (err === 0) {
        this.loading = false;
        this.tableData = data.data;
        this.page.pageSize = data.per_page;
        this.page.total = data.total;
      }
    },
    //添加
    handleAdd() {
      this.rowData = {};
      this.changeDialog = true;
      this.title = "新增";
    },
    //关闭编辑
    closeAddSettle() {
      this.changeDialog = false;
      this.settleList();
    },
    //编辑
    handleEdit(row) {
      this.rowData = row;
      this.changeDialog = true;
    },

    // 当前页: ${val}
    handleCurrentChange(val) {
      this.page.pageNum = val;
      this.loading = true;
      this.store_list();
    },
  },
  created() {
    this.settleList();
  },
};
</script>

<style lang="scss" scoped>
@import "@/style/index.scss";
.handleExamine {
  margin-left: 20px;
}
.info {
  .title {
    font-size: 16px;
    margin-bottom: 13px;
  }
}
.pagination {
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
}
.el-select {
  width: 100%;
}

.tb {
  background-color: #fff;
  padding: 20px;
  box-sizing: border-box;
}
.row {
  display: flex;
  align-items: center;
  border-radius: 2px;
  .l {
    padding: 8px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ccc;
    font-size: 13px;
    i {
      margin-right: 6px;
      font-size: 13px;
    }
    &:hover {
      cursor: pointer;
    }
  }
  .tip {
    color: #999999;
    margin-left: 20px;
    font-size: 13px;
  }
}
.caozuo {
  display: flex;
  justify-content: center;
  .handleDelete {
    margin-left: 20px;
  }
}
.detailDialog,
.editDialog {
  /deep/.el-dialog {
    height: 82%;
    margin-top: 10vh !important;
    .el-dialog__body {
      height: 80%;
      overflow: auto;
    }
  }
}

.beizhu {
  padding: 0 20px 50px 20px;
  box-sizing: border-box;
  .bz {
    margin-bottom: 10px;
    margin-top: 20px;
  }
  .btn {
    margin-top: 20px;
    .el-button {
      width: 100%;
    }
  }
}
</style>
